<?php

$key = $_REQUEST["key"];
$s = $_REQUEST["s"];

switch ($key) {
    case "":


        break;

    default:
        break;
}
$db = new myDBS;
//$db->selectDB("account");
//
//$result1 = $db->runSQL($sql);
//$row = $db->fetch_object($result1);
//
//$bank = $_REQUEST['bank_name'];
//
//if ($bank) {
//    foreach ($bank as $b) {
//        echo $b . "<br>";
//    }
//}
?>

<script type="text/javascript">
    $(document).ready(function() {
        $("#i_date").datepicker({
            dateFormat: "yy-mm-dd",
            showButtonPanel: true
        });
        
        $("#save_changes").click(function() {
            event.preventDefault();

            var i_date = $("#i_date").val();
            
            var bank = [];
            $("select[name^='bank_name[]']").each(function() {
                //alert($(this).val());
                bank.push($(this).val());
            });

            var branch = [];
            $("select[name^='branch_name[]']").each(function() {
                //alert($(this).val());
                branch.push($(this).val());
            });

            var bank_type = [];
            $("select[name^='bank_type[]']").each(function() {
                //alert($(this).val());
                bank_type.push($(this).val());
            });
            var a = [];
            $("input[name^='a[]']").each(function() {
                a.push($(this).val());
                //alert($(this).val());
            });
            
            var c = [];
            $("input[name^='c[]']").each(function() {
                c.push($(this).val());
                //alert($(this).val());
            });

            $.ajax({
                type: "POST",
                url: "chq_salary_process",
                data: {bank: bank
                    , branch: branch
                    , bank_type: bank_type
                    , a: a
                    , c: c
                    , i_date: i_date
                },
                cach: false,
                error: function() {
                    alert("ERROR !!!!");
                },
                success: function(data) {
                    $("#test").html(data)

//                    window.location.href = "index.php?pages=chq_salary";
                }
            });
        });
    });
</script>

<div id="test"></div>
<form action="index.php" >
    <input type="hidden" name="pages" value="chq_salary_save">
    <div class="row-fluid">
        <div class="control-group span6">
            <label class="control-label" for="จำนวนเงิน">จำนวนเงิน</label>
            <div class="controls">
                <input type="text" class="span12 text-right" id="amount" name="amount" value="<?php echo $s; ?>" readonly=""/>
            </div>
        </div>
        <div class="control-group span3">
            <label class="control-label" for="ผู้รับเงิน">ผู้รับเงิน</label>
            <div class="controls">
                <input type="text" class="span12" id="receiver" name="receiver" value="<?php echo $receiver; ?>" readonly=""/>
            </div>
        </div>
        <div class="control-group span3">
            <label class="control-label" for="วันที่">วันที่</label>
            <div class="controls">
                <input class="span12" type="text" id="i_date" name="i_date" />
            </div>
        </div>
    </div>
    <div class="row-fluid">
        <div class="control-group span4">
            <label>ธนาคาร</label>
            <div class="controls">
                <select class="span12" id="bank_name" name="bank_name[]" >
                    <?php
                    $result = $db->showData("bank");
                    while ($rows = $db->fetch_object($result)) {
                        echo "<option value='$rows->bank_id'>$rows->bank_name</option>";
                    }
                    ?>
                </select>
            </div>
        </div>

        <div class="control-group span2">
            <label>สาขา</label>
            <div class="controls">
                <select class="span12" id="branch_name" name="branch_name[]" >
                    <?php
                    $result = $db->showData("bank_branch");

                    while ($rows = $db->fetch_object($result)) {
                        echo "<option value='$rows->bank_branch_id'>$rows->branch_name</option>";
                    }
                    ?>
                </select>
            </div>
        </div>
        <div class="control-group span2">
            <label>ประเภทบัญชี</label>
            <div class="controls">
                <select class="span12" id="bank_type" name="bank_type[]" >
                    <option value="">เลือก...</option>
                    <?php
                    $sql = "SELECT DISTINCT bank_type "
                            . " FROM bank_account "
                            . " ";
                    $result = $db->runSQL($sql);

                    while ($rows = $db->fetch_object($result)) {
                        echo "<option>$rows->bank_type</option>";
                    }
                    ?>
                </select>
            </div>
        </div>
        <div class="control-group span2">
            <label>เลขที่เช็ค/เลขที่บัญชี</label>
            <div class="controls">
                <input type="text" class="span12 " id="c" name="c[]">
            </div>
        </div>
        <div class="control-group span2">
            <label>จำนวนเงิน</label>
            <div class="controls">
                <input type="text" class="span12 text-right" id="a" name="a[]" value="<?php echo ($dis_multi) ? $row->net : ""; ?>">
            </div>
        </div>
    </div>

    <div class="row-fluid <?php echo ($dis_multi) ? " hide" : ""; ?>">
        <div class="control-group span4">
            <label>ธนาคาร</label>
            <div class="controls">
                <select class="span12" id="bank_name" name="bank_name[]" >
                    <?php
                    $result = $db->showData("bank");
                    while ($rows = $db->fetch_object($result)) {
                        echo "<option value='$rows->bank_id'>$rows->bank_name</option>";
                    }
                    ?>
                </select>
            </div>
        </div>

        <div class="control-group span2">
            <label>สาขา</label>
            <div class="controls">
                <select class="span12" id="branch_name" name="branch_name[]" >
                    <?php
                    $result = $db->showData("bank_branch");

                    while ($rows = $db->fetch_object($result)) {
                        echo "<option value='$rows->bank_branch_id'>$rows->branch_name</option>";
                    }
                    ?>
                </select>
            </div>
        </div>
        <div class="control-group span2">
            <label>ประเภทบัญชี</label>
            <div class="controls">
                <select class="span12" id="bank_type" name="bank_type[]" >
                    <option value="">เลือก...</option>
                    <?php
                    $sql = "SELECT DISTINCT bank_type "
                            . " FROM bank_account "
                            . " ";
                    $result = $db->runSQL($sql);

                    while ($rows = $db->fetch_object($result)) {
                        echo "<option>$rows->bank_type</option>";
                    }
                    ?>
                </select>
            </div>
        </div>
        <div class="control-group span2">
            <label>เลขที่เช็ค/เลขที่บัญชี</label>
            <div class="controls">
                <input type="text" class="span12" id="c" name="c[]">
            </div>
        </div>
        <div class="control-group span2">
            <label>จำนวนเงิน</label>
            <div class="controls">
                <input type="text" class="span12 text-right" id="a" name="a[]">
            </div>
        </div>
    </div>
    <div class="row-fluid <?php echo ($dis_multi) ? " hide" : ""; ?>">
        <div class="control-group span4">
            <label>ธนาคาร</label>
            <div class="controls">
                <select class="span12" id="bank_name" name="bank_name[]" >
                    <?php
                    $result = $db->showData("bank");
                    while ($rows = $db->fetch_object($result)) {
                        echo "<option value='$rows->bank_id'>$rows->bank_name</option>";
                    }
                    ?>
                </select>
            </div>
        </div>

        <div class="control-group span2">
            <label>สาขา</label>
            <div class="controls">
                <select class="span12" id="branch_name" name="branch_name[]" >
                    <?php
                    $result = $db->showData("bank_branch");

                    while ($rows = $db->fetch_object($result)) {
                        echo "<option value='$rows->bank_branch_id'>$rows->branch_name</option>";
                    }
                    ?>
                </select>
            </div>
        </div>
        <div class="control-group span2">
            <label>ประเภทบัญชี</label>
            <div class="controls">
                <select class="span12" id="bank_type" name="bank_type[]" >
                    <option value="">เลือก...</option>
                    <?php
                    $sql = "SELECT DISTINCT bank_type "
                            . " FROM bank_account "
                            . " ";
                    $result = $db->runSQL($sql);

                    while ($rows = $db->fetch_object($result)) {
                        echo "<option>$rows->bank_type</option>";
                    }
                    ?>
                </select>
            </div>
        </div>
        <div class="control-group span2">
            <label>เลขที่เช็ค/เลขที่บัญชี</label>
            <div class="controls">
                <input type="text" class="span12" id="c" name="c[]">
            </div>
        </div>
        <div class="control-group span2">
            <label>จำนวนเงิน</label>
            <div class="controls">
                <input type="text" id="a" class="span12 text-right" name="a[]">
            </div>
        </div>
    </div>
    <button class="btn btn-info" id="save_changes" name="save_changes">บันทึก</button>
</form>
